package cn.com.bluemoon.daps.domp.api.param;

import cn.com.bluemoon.daps.common.toolkit.BmAssetUtils;
import cn.com.bluemoon.daps.common.validation.JValidUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 橘色包装工
 *
 * @author Jarod.Kong
 * @date 2021/7/23 13:38
 */
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class RoleParamPacker implements Serializable, DompParamToMap {
    private static final long serialVersionUID = 1L;
    @NotNull(message = "入参不可为空")
    private String token, userAccount;

    /**
     * model to Map and set method code
     * @param methodCode mcode
     * @return map
     */
    @Override
    public Map<String, Object> toMap(String methodCode) {
        List<String> predicate = JValidUtils.INSTANCE.validate(this);
        BmAssetUtils.isTrue(predicate.isEmpty(), predicate.toString());
        return new HashMap<String, Object>() {{
            put("id", userAccount);
            put("token", token);
            put("method", methodCode);
        }};
    }

    @Override
    public String toString() {
        return ReflectionToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
    }
}

